package logic

import (
	"context"
	"product2/model/mysql"
	"product2/userrpc/internal/svc"
	"product2/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProAddLogic {
	return &ProAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProAddLogic) ProAdd(in *userrpc.ProAddRequest) (*userrpc.ProAddResponse, error) {
	// todo: add your logic here and delete this line

	var proadd = mysql.Product{
		Name:   in.Name,
		Price:  in.Price,
		Title:  in.Title,
		UserId: in.UserId,
		Text:   in.Text,
	}
	mysql.DB.Create(&proadd)

	return &userrpc.ProAddResponse{Id: int64(proadd.ID)}, nil
}
